package com.zb.controller;


import com.zb.common.R;
import com.zb.entity.Category;
import com.zb.entity.PageData;
import com.zb.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    //添加菜品分类
    @PostMapping("/add")
    public R<Boolean> addCatrgory(@RequestBody Category category) {
        Integer num = categoryService.addCategorys(category);
        return R.success(num > 0, "添加成功");
    }

    //查询菜品分类
    @GetMapping("/select")
    public R<PageData> selectCategory(Integer page, Integer pageSize) {
        PageData categoryList = categoryService.pageSelectCategory(page, pageSize);
        return R.success(categoryList, "查询菜品成功");
    }

    //根据id查询分类菜单详情
    @GetMapping("/{id}")
    public R<Category> getCategoryById(@PathVariable Long id) {
        Category cate = categoryService.getCategoryById(id);
        return R.success(cate, "查询分类成功");
    }

    //根据id修改分类菜品信息
    @PutMapping
    public R<Boolean> updateCategoryDetail(@RequestBody Category category) {
        int num = categoryService.updateCategory(category);
        return R.success(num > 0, "关系菜品分类成功");
    }
}
